package com.itbaizhan.cxpt.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.itbaizhan.cxpt.entity.CxptBz;
import com.itbaizhan.cxpt.service.CxptBzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/standard")
public class CxptBzController {

    @Autowired
    private CxptBzService cxptBzService;

    @GetMapping("/page")
    public IPage<CxptBz> pageQuery(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String keyword) {
        return cxptBzService.pageQuery(page, size, keyword);
    }

    @GetMapping("/standard-no/{standardNo}")
    public CxptBz getByStandardNo(@PathVariable String standardNo) {
        return cxptBzService.getByStandardNo(standardNo);
    }

    @GetMapping("/by-date")
    public List<CxptBz> queryByPublishDate(
            @RequestParam(required = false) String startDate,
            @RequestParam(required = false) String endDate) {
        return cxptBzService.queryByPublishDateRange(startDate, endDate);
    }

    @GetMapping("/{id}")
    public CxptBz getById(@PathVariable Integer id) {
        return cxptBzService.getById(id);
    }
}